package com.wjh.kt_vod.controller;

import com.wjh.kt_vod.model.vod.Chapter;
import com.wjh.kt_vod.result.Result;
import com.wjh.kt_vod.service.ChapterService;
import com.wjh.kt_vod.vo.vod.ChapterVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "章节管理")
@RestController
@RequestMapping("/admin/vod/chapter")
public class ChapterController {

    @Autowired
    @Qualifier("chapterServiceImpl")
    private ChapterService chapterService;

    //大纲列表（章节和小结）
    @ApiOperation("大纲列表")
    @GetMapping("getNestedTreeList/{courseId}")
    public Result getNestedTreeList(@ApiParam(name = "courseId", value = "课程id", required = true)
                                    @PathVariable("courseId") Long courseId) {
        List<ChapterVo> list = chapterService.getTreeList(courseId);
        return Result.ok(list);
    }

    //    添加章节
    @ApiOperation("添加章节")
    @PostMapping("/save")
    public Result save(@RequestBody Chapter chapter) {
        boolean save = chapterService.save(chapter);
        return Result.ok(save);
    }

    //3 修改-根据id查询
    @ApiOperation(value = "根据id查询")
    @GetMapping("get/{id}")
    public Result get(@PathVariable("id")
                      @ApiParam(name = "id", value = "章节id" ,required = true) Long id) {
        Chapter byId = chapterService.getById(id);
        return Result.ok(byId);
    }

    //    修改
    @ApiOperation(value = "修改章节")
    @PostMapping("/update")
    public Result updateChapter(@RequestBody Chapter chapter) {
        chapterService.updateById(chapter);
        return Result.ok();
    }

    //    删除章节
    @ApiOperation(value = "删除章节")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable("id")
                         @ApiParam(name = "id", value = "章节id" ,required = true) Long id) {
        chapterService.removeAndVideoAndVodById(id);
        return Result.ok();
    }


}
